import echarts from 'echarts'
import { debug } from 'util';
import { stat } from 'fs';
export default {

    addSeriesDataValue(state, opt) {
        state.viewList.forEach(function(ele, index) {

            if (ele.uid == opt.id) {
                var length = ele.option.series.length;
                if (ele.option.series[0].data) {
                    ele.option.series[0].data[opt.order].value = opt.value;
                } else {
                    return
                }
            }
            console.log(ele.option)
        })
    },
    addSeriesList(state, opt) {
        state.viewList.forEach(function(ele, index) {

            if (ele.uid == opt.id) {

                ele.option.seriesList.push(opt.obj);

            }
            console.log(ele.option)
        })
    },
    changeAllViewList(state, obj) {
        state.viewList = obj
    },
    changeBorderActive(state, status) {
        state.borderActive = status;
    },
    getViewList(state, array) {
        state.viewList = array;
    },
    changeEmptyActive(state, states) {
        state.emptyViewActive = states;
    },
    changeMaskShow(state, states) {
        state.maskStyle.maskShow = states;
    },
    changeShowState(state, states) {
        state.showState = states;
    },
    addViewList(state, obj) {
        state.viewList.push(obj);
    },
    removeViewEcharts(state, id){
        // 获取当前DOM上的实例
        // let myChart = echarts.getInstanceByDom(ele);
        
        // 销毁当前echarts实例
        // if(myChart != undefined){
        //     myChart.dispose();
        //     // ele.parentNode.remove();
        // }
        for(let key in state.echartsObj) {
            if(state.echartsObj[key].id == id){
                let myChart = state.echartsObj[key].chart;
                myChart.dispose();
            }
        }
        // let myChart = state.echartsObj
    },
    removeViewList(state, index) {
        state.viewList.splice(index, 1)
    },
    changeViewIframeSrc(state, str) {
        state.viewIframeSrc = str;
    },
    changeClickIsActive(state, $index) {
        state.viewList.forEach(function(ele, index) {
            ele.isActive = false;
        })
        state.viewList[$index].isActive = !state.viewList[$index].isActive;
    },
    changeEditIndexId(state, id) {
        state.editIndexId = id;
    },
    changeShowControl(state, status) {
        state.showControl = status;
    },
    addKpiTreeData(state, obj) {
        console.log('aaaaaaaaaaaaaaa')
        console.log(obj)
        state.kpiTreeData = obj.data;
    },
    changeKpiIndex(state, str) {
        state.kpiIndex = str;
    },
    getLoadEchartsData(state, obj) {
        state.loadEchartsData = obj;
    },
    getViewList (state, obj) {
        state.viewList = obj
    },
    changeSave (state) {
        state.saveStatus = !state.saveStatus
    },
    changeEdit (state) {
        state.editStatus = !state.editStatus
    },
    deteleView(state, index) {
        console.log(index)
        state.viewList.splice(index, 1)
    },
    addView(state, obj) {
        state.viewList.push(obj)
    },
    addEchartsObj(state, obj) {
        state.echartsObj.push(obj)
    },
    getKpiData(state, obj){
        state.kpiData = obj
    },
    loadKpiData(state, str) {
        console.log(str)
        for(let key in state.kpiTreeData) {
            console.log(state.kpiTreeData[key].name )
            if(state.kpiTreeData[key].name == str) {
                console.log('=================')
                
                state.kpiData = state.kpiTreeData[key]
            }
        }
    }

}


// 724991599@qq.com 
// Menghuanren1234